/**
 * Software License Agreement (MIT License)
 * 
 * Copyright (c) 2022, UFACTORY, Inc.
 * 
 * All rights reserved.
 * 
 * @author Zhang <jimy92@163.com>
 * @author Vinman <vinman.wen@ufactory.cc> <vinman.cub@gmail.com>
 */

#define _CRT_SECURE_NO_WARNINGS

#include <stdarg.h>
#include "xarm/core/debug/debug_print.h"
#include "xarm/core/common/data_type.h"

#define DB_FLG "[deprint ] "
#define PRINTF_NUM_MAX 128
#define log_put printf

void print_log(const char *format, ...) {
  char buffer[PRINTF_NUM_MAX] = { 0 };
  va_list arg;
  va_start(arg, format);
  vsnprintf(buffer, PRINTF_NUM_MAX, format, arg);
  printf("%s", buffer);
  va_end(arg);
}

void print_nvect(const char *str, double vect[], int n) {
  print_log("%s", str);
  for (int i = 0; i < n; ++i) { print_log("%0.3f ", vect[i]); }
  print_log("\n");
}

void print_nvect(const char *str, float *vect, int n) {
  print_log("%s", str);
  for (int i = 0; i < n; ++i) { print_log("%0.3f ", vect[i]); }
  print_log("\n");
}

void print_nvect(const char *str, unsigned char vect[], int n) {
  print_log("%s", str);
  for (int i = 0; i < n; ++i) { print_log("%d ", vect[i]); }
  print_log("\n");
}

void print_nvect(const char *str, int vect[], int n) {
  print_log("%s", str);
  for (int i = 0; i < n; ++i) { print_log("%d ", vect[i]); }
  print_log("\n");
}

void print_hex(const char *str, unsigned char *hex, int len) {
  // char buf[len * 3 + 1] = {'\0'};
  char *buf = new char[len * 3 + 1]();
  long i;
  for (i = 0; i < len; ++i) { sprintf((char *)&buf[i * 3], "%02x ", hex[i]); }

  printf("%s %s\n", str, buf);
  delete[] buf;
}
